package com.ruoyi.project.datamanagement.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.datamanagement.domain.DataSources;
import com.ruoyi.project.datamanagement.service.IDataSourcesService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 数据源Controller
 * 
 * @author anan
 * @date 2021-01-09
 */
@RestController
@RequestMapping("/datamanagement/dataSources")
public class DataSourcesController extends BaseController
{
    @Autowired
    private IDataSourcesService dataSourcesService;

    /**
     * 查询数据源列表
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:query')")
    @GetMapping("/list")
    public TableDataInfo list(DataSources dataSources)
    {
        startPage();
        List<DataSources> list = dataSourcesService.selectDataSourcesList(dataSources);
        return getDataTable(list);
    }

    /**
     * 查询数据源列表
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:query')")
    @GetMapping("/allList")
    public TableDataInfo allList(DataSources dataSources)
    {
        List<DataSources> list = dataSourcesService.selectDataSourcesList(dataSources);
        return getDataTable(list);
    }

    /**
     * 导出数据源列表
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:export')")
    @Log(title = "数据源", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DataSources dataSources)
    {
        List<DataSources> list = dataSourcesService.selectDataSourcesList(dataSources);
        ExcelUtil<DataSources> util = new ExcelUtil<DataSources>(DataSources.class);
        return util.exportExcel(list, "sources");
    }

    /**
     * 获取数据源详细信息
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dataSourcesService.selectDataSourcesById(id));
    }

    /**
     * 新增数据源
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:add')")
    @Log(title = "数据源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataSources dataSources)
    {
        return toAjax(dataSourcesService.insertDataSources(dataSources));
    }

    /**
     * 修改数据源
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:edit')")
    @Log(title = "数据源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataSources dataSources)
    {
        return toAjax(dataSourcesService.updateDataSources(dataSources));
    }

    /**
     * 删除数据源
     */
    @PreAuthorize("@ss.hasPermi('datamanagement:dataSources:remove')")
    @Log(title = "数据源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dataSourcesService.deleteDataSourcesByIds(ids));
    }
}
